package com.xc.hotelmgr.webapi.modules.dt.controller;

import java.util.*;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xc.hotelmgr.webapi.modules.dt.entity.DtEntity;
import com.xc.hotelmgr.webapi.modules.dt.service.DtService;
import com.xc.hotelmgr.webapi.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.xc.hotelmgr.webapi.modules.dt.entity.StorePfEntity;
import com.xc.hotelmgr.webapi.modules.dt.service.StorePfService;
import com.xc.hotelmgr.webapi.common.utils.PageUtils;
import com.xc.hotelmgr.webapi.common.utils.R;



/**
 * 销售平台
 *
 * @author kemmy
 * @email kemmy@gmail.com
 * @date 2020-09-13 18:49:30
 */
@RestController
@RequestMapping("dt/storepf")
public class StorePfController extends AbstractController{
    @Autowired
    private StorePfService storePfService;

    @Autowired
    private DtService dtService;

    @RequestMapping(value = "/list/pf", method = RequestMethod.GET)
    public R listPf () {
        Integer dtId = getUserDtId();
        List<StorePfEntity> storePfEntities = storePfService.list();
        return R.ok().put("list", storePfEntities).put("dtId", dtId);
    }

    /**
     * 查询 所属分销商和所属平台下拉树
     */
    @RequestMapping("/query")
    public R listBox() {
        String inSql = "SELECT id FROM dt_dt WHERE FIND_IN_SET(id, getChild("+  getUserDtId()+ "))";
        List<DtEntity> dts =  dtService.getBaseMapper().selectList(new QueryWrapper<DtEntity>().inSql("id",inSql));
        List<StorePfEntity> spfs = storePfService.getBaseMapper().selectList(new QueryWrapper<StorePfEntity>());
        return R.ok().put("dts", dts).put("spfs",spfs);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("dt:storepf:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = storePfService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("dt:storepf:info")
    public R info(@PathVariable("id") Integer id){
		StorePfEntity storePf = storePfService.getById(id);

        return R.ok().put("storePf", storePf);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("dt:storepf:save")
    public R save(@RequestBody StorePfEntity storePf){
		storePfService.save(storePf);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("dt:storepf:update")
    public R update(@RequestBody StorePfEntity storePf){
		storePfService.updateById(storePf);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("dt:storepf:delete")
    public R delete(@RequestBody Integer[] ids){
		storePfService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
